﻿/***********************************************************************
 * 描述: DropDownButtonWidget 功能测试界面
 * File:    dropdownbuttonwidget.cpp
 * Author:  gaomaolong@mozihealthcare.cn
 * Date:    25-10-15 下午1:37
 * Version: 1.0
 **********************************************************************/

#include "dropdownbuttonwidget.h"
#include "ui_dropdownbuttonwidget.h"
#include <QAction>
#include <QDebug>
#include <controls/dropdownbutton/cxidropdownbutton.h>

DropDownButtonWidget::DropDownButtonWidget(QWidget* parent)
	: QWidget(parent),
	  ui(new Ui::DropDownButtonWidget)
{
	ui->setupUi(this);

	// --- 设置下拉按钮的基本外观 ---
	ui->cxiDropDownButton->setText("配置项菜单");

	// --- 连接信号槽 ---
	connect(ui->pushButton, &QPushButton::clicked, this, [this]() {
		ui->cxiDropDownButton->addItem("无图标项", QIcon(), [this]() {
			ui->textBrowser->append("点击了『无图标项』");
		});
		ui->textBrowser->append("✅ 已添加『无图标项』");
	});

	connect(ui->pushButton_2, &QPushButton::clicked, this, [this]() {
		QIcon icon(":/icon/menu/pacs.png");
		ui->cxiDropDownButton->addItem("带图标项", icon, [this]() {
			ui->textBrowser->append("点击了『带图标项』");
		});
		ui->textBrowser->append("✅ 已添加『带图标项』");
	});

	connect(ui->pushButton_3, &QPushButton::clicked, this, [this]() {
		QIcon icon(":/icon/menu/pacs.png");
		QAction* action = new QAction(icon, "带回调项", this);
		connect(action, &QAction::triggered, [this]() {
			ui->textBrowser->append("点击了『action绑定的项目』");
		});
		action->setShortcut(QKeySequence::Save);
		ui->cxiDropDownButton->addItem(action);
		ui->textBrowser->append("✅ 已添加『action项目』");
	});

	connect(ui->pushButton_4, &QPushButton::clicked, this, [this]() {
		int index = 1;
		ui->cxiDropDownButton->addItem("插入到 index=1 的项", QIcon(), [this]() { ui->textBrowser->append("点击了『插入项』"); }, index);
		ui->textBrowser->append(QString("✅ 已在 index=%1 插入项").arg(index));
	});

	connect(ui->pushButton_6, &QPushButton::clicked, this, [this]() {
		ui->cxiDropDownButton->addSeparator();
		ui->textBrowser->append("✅ 已添加分隔符");
	});
}

DropDownButtonWidget::~DropDownButtonWidget()
{
	delete ui;
}
